/**
 * 
 */
package com.cglib;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

/**
 * @author lionbule
 * 
 */
public class TestCglib {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(TestClass.class);
		enhancer.setCallback(new MethodInterceptorImpl());
		TestClass my = (TestClass) enhancer.create();
		my.print("lionbule nick.");
	}

	private static class MethodInterceptorImpl implements MethodInterceptor {
		public Object intercept(Object obj, Method method, Object[] args,
				MethodProxy proxy) throws Throwable {
			proxy.invokeSuper(obj, args);
			System.out.println(method + " intercepted!");
			proxy.invokeSuper(obj, args);
			return null;
		}
	}
	
}
